package com.ansion.baseui.base;

import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ansion.basetool.preconditions.Preconditions;
import com.ansion.log.VLog;

/**
 * created by zhaoyuntao
 * on 13/10/2022
 * description:
 */
public abstract class BroadcastProcessor {
    private final String action;

    public BroadcastProcessor(@NonNull String action) {
        Preconditions.checkNotEmpty(action);
        this.action = action;
    }

    final public void setParam(@NonNull IntentFilter intentFilter) {
        intentFilter.addAction(action);
    }

    public abstract void onProcess(@NonNull Intent intent);

    final protected boolean matched(@Nullable String action) {
        if (TextUtils.isEmpty(action)) {
            VLog.e("TAG_USAGE", "BroadcastProcessor matched an empty action:" + Log.getStackTraceString(new Throwable()));
            return false;
        }
        return TextUtils.equals(action, this.action);
    }
}
